package de.clapp.musicbox;

import de.clapp.CLAppModel;
import de.clapp.Settings;
import de.clapp.backend.network.ClientRequest;
import de.clapp.backend.network.TCPSocket;
import de.clapp.backend.requests.MusicVoteRequest;
import de.clapp.data.Club;
import de.clapp.data.MusicItem;

public class MusicVoteThread extends Thread
{
    private MusicItem item;

    public MusicVoteThread(MusicItem item)
    {
        this.item = item;
    }

    @Override
    public void run()
    {
        MusicVoteRequest request = new MusicVoteRequest(this.item);
        Club club = CLAppModel.getInstance().getCurrentClub();
        try
        {
            final ClientRequest cr = new ClientRequest(new TCPSocket(club.getIpAddress(), club.getPort()));

            Thread t = new Thread()
            {
                @Override
                public void run()
                {
                    try
                    {
                        Thread.sleep(1000);
                        cr.close();
                    }
                    catch (Exception e)
                    {

                    }
                }
            };

//            t.start();
            
            cr.request(request);
            cr.close();

        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}